import array
import os

#symbols = '$\u00A2\u00A3\u00A5\u20AC\u00A4'
symbols = '$¢£¥€¤'
codes = []
for symbol in symbols:
    codes.append(ord(symbol))
print(codes)
codess =[ord(symbol) for symbol in symbols]
print(codess)
beyond_ascii = [ord(s) for s in symbols if ord(s) > 126]
print(beyond_ascii)
beyond_ascii = list(filter(lambda c: c>127,map(ord,symbols)))
print(beyond_ascii)

x = 'my precious'
dummy = [x for x in 'ABC']
print(x)
print(dummy)


y = 'ABC'
dummy = [ord(y) for y in y]
print(y)
print(dummy)

#笛卡尔积
colors =['black','white']
sizes = ['S','M',"L"]
tshirts = [(color,size) for color in colors 
                        for size in sizes]
print(tshirts)
tshirts =[(color,size) for size in sizes
                       for color in colors]
print(tshirts)

for tshirt in ('%s %s' %(c,s) for c in colors for s in sizes):
    print(tshirt)


symbols = '$¢£¥€¤'
print(tuple(ord(symbol) for symbol in symbols))
print(array.array('I',(ord(symbol) for symbol in symbols)))

lax_coordinates = (33.9425,-118.408056)
city,year,pop,chg,area = ('Tokyo',2003,32450,0.66,8014)
traveler_ids = [('USA','31195855'),('BRA','CE342567'),('ESP','XDA205856')]
for passport in sorted(traveler_ids):
    print('%s/%s' % passport)
for country,_ in traveler_ids:
    print(country)

#元组拆包
lax_coordinates = (33.9425,-118.408056)
latitude,longitude = lax_coordinates
print(latitude)
print(longitude)
#交换变量
latitude,longitude = longitude,latitude
print(latitude)
print(longitude)

#(2,4)
print(divmod(20,8))

t = (20,8)
print(divmod(*t))

quotient,remainder = divmod(*t)
print(quotient)
print(remainder)

_, filename = os.path.split('/home/luciano/.ssh/idrsa.pub')
print(filename)

a,b,*rest = range(5)
print(a)
print(b)
print(rest)

a,b,*rest = range(3)
print(a)
print(b)
print(rest)

a,*body,c,d = range(5)
print(a)
print(body)
print(c)
print(d)

*head,b,c,d = range(5)
print(head)
print(b)
print(c)
print(d)

metro_areas=[
    ('Tokyo','JP',36.933,(35.689722,139.691667)),
    ('Delhi NCR', 'IN', 21.935, (28.613889, 77.208889)), 
    ('Mexico City', 'MX', 20.142, (19.433333, -99.133333)), 
    ('New York-Newark', 'US', 20.104, (40.808611, -74.020386)), 
    ('Sao Paulo', 'BR', 19.649, (-23.547778, -46.635833)),
]
print('{:15} | {:^9} | {:^9}'.format('','lat.','long.'))
fmt = '{:15} | {:9.4f} | {:9.4f}'
for name, cc,pop,(layitude,longitude) in metro_areas:
    if longitude <= 0:
        print(fmt.format(name,latitude,longitude))

